package com.uaf.vxalipaybill.provider.service.write.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.uaf.log.MySlf4j;
import com.uaf.vxalipaybill.api.exception.VxAlipayBillException;
import com.uaf.vxalipaybill.api.exception.VxAlipayBillServiceException;
import com.uaf.vxalipaybill.provider.bean.VxAlipayAnalysisDetailBean;
import com.uaf.vxalipaybill.provider.dao.VxAlipayAnalysisDetailBeanDao;
import com.uaf.vxalipaybill.provider.service.write.IShardingJdbcVxAlipayBillWriteService;

/**
 * @filename VxShardingjdbcAlipayBillWriteServiceImpl.java
 * @description 微信支付宝账单分表数据迁移
 * @author 马庆智
 * @date 2021/9/15 11:06
 */
@Service
public class VxShardingjdbcAlipayBillWriteServiceImpl implements IShardingJdbcVxAlipayBillWriteService {

	@Autowired
	private VxAlipayAnalysisDetailBeanDao vxAlipayAnalysisDetailBeanDao;

	/***
	 * 功能描述 分表数据迁移
	 * @param list 要迁移的bean集合
	 * @return void
	 * @author 马庆智
	 * @date 2022/3/29 9:31
	 */
	@Override
	@Transactional
	public void insertShardingJdbc(List<VxAlipayAnalysisDetailBean> list){
       for (int i=0;i<list.size();i++){
       	  try {
	          vxAlipayAnalysisDetailBeanDao.moveVxAlipayAnalysisDetailBean(list.get(i));
          }catch (Exception e){
	          MySlf4j.textError("VxShardingjdbcAlipayBillWriteServiceImpl,保存过程异常,保存的billAnalysisReqId为:{0},异常原因:{1},请手动处理后再运行",list.get(i).getBillAnalysisReqId(),
			          MySlf4j.ExceptionToString(e));
	          throw new VxAlipayBillServiceException(VxAlipayBillException.ERR_JDBC001);
          }
       }
    }
}
